package com.gxedu.springenvironmentconfig.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: Liu_gx
 * @Date: 2021/1/28 16:34
 * @Description:
 */
@RestController
public class TestController {

//    @Value("${java.version}")//获取环境变量
    @Value("${envtest}")//获取环境变量
    private String version;

    @Value("${custom.property.hello}")//自定义配置文件
    private String txt;

    @Autowired
    private Environment environment;

    @GetMapping("/test")
    public String test(){
        return environment.getProperty("java.version"); //1.8.0_191
//        return version;//1.8.0_191
    }

    @GetMapping("/txt")
    public String txt(){
        return txt; //hello test

    }
}
